Use unique_ptr over scoped pointer
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 28 Nov 2024 09:53:24 +0000 (17:53 +0800)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Fri, 20 Dec 2024 15:26:57 +0000 (16:26 +0100)
take is deprecated in scoped pointer

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
f handle

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
Use unique_ptr instead of scoped pointer for propagator firstJob

Fixes deprecation warning

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
Use unique_ptr for discoveryphase, replace take with release

Fix deprecation warn

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
f unique

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/csync/vio/csync_vio_local_unix.cpp
src/gui/wizard/flow2authwidget.cpp
src/gui/wizard/flow2authwidget.h
src/libsync/owncloudpropagator.cpp
src/libsync/owncloudpropagator.h
src/libsync/syncengine.cpp
src/libsync/syncengine.h

index ec47ab3c7c994e89f626b8977f4a19d02a8b4e45..8f319a3e4b23f4a01259e32523ec316bad05c520 100644 (file)
@@ -52,8 +52,7 @@ struct csync_vio_handle_t {
 static int _csync_vio_local_stat_mb(const mbchar_t *wuri, csync_file_stat_t *buf);
 
 csync_vio_handle_t *csync_vio_local_opendir(const QString &name) {
-    QScopedPointer<csync_vio_handle_t> handle(new csync_vio_handle_t{});
-
+    auto handle = std::make_unique<csync_vio_handle_t>();
     auto dirname = QFile::encodeName(name);
 
     handle->dh = _topendir(dirname.constData());
@@ -62,7 +61,7 @@ csync_vio_handle_t *csync_vio_local_opendir(const QString &name) {
     }
 
     handle->path = dirname;
-    return handle.take();
+    return handle.release();
 }
 
 int csync_vio_local_closedir(csync_vio_handle_t *dhandle) {
index 87f63d59197a8be51add40ad346a76d1b1be5cd6..cb9262846d9713135e437fcd4d4e905aece2e605 100644 (file)
@@ -65,19 +65,20 @@ void Flow2AuthWidget::setLogo()
 
 void Flow2AuthWidget::startAuth(Account *account)
 {
-    Flow2Auth *oldAuth = _asyncAuth.take();
-    if(oldAuth)
+    const auto oldAuth = _asyncAuth.release();
+    if (oldAuth) {
         oldAuth->deleteLater();
+    }
 
     _statusUpdateSkipCount = 0;
 
     if(account) {
         _account = account;
 
-        _asyncAuth.reset(new Flow2Auth(_account, this));
-        connect(_asyncAuth.data(), &Flow2Auth::result, this, &Flow2AuthWidget::slotAuthResult, Qt::QueuedConnection);
-        connect(_asyncAuth.data(), &Flow2Auth::statusChanged, this, &Flow2AuthWidget::slotStatusChanged);
-        connect(this, &Flow2AuthWidget::pollNow, _asyncAuth.data(), &Flow2Auth::slotPollNow);
+        _asyncAuth = std::make_unique<Flow2Auth>(_account, this);
+        connect(_asyncAuth.get(), &Flow2Auth::result, this, &Flow2AuthWidget::slotAuthResult, Qt::QueuedConnection);
+        connect(_asyncAuth.get(), &Flow2Auth::statusChanged, this, &Flow2AuthWidget::slotStatusChanged);
+        connect(this, &Flow2AuthWidget::pollNow, _asyncAuth.get(), &Flow2Auth::slotPollNow);
         _asyncAuth->start();
     }
 }
@@ -122,7 +123,7 @@ void Flow2AuthWidget::setError(const QString &error) {
 
 Flow2AuthWidget::~Flow2AuthWidget() {
     // Forget sensitive data
-    _asyncAuth.reset();
+    _asyncAuth.reset(nullptr);
 }
 
 void Flow2AuthWidget::slotOpenBrowser()
index 2660ff0b76209810621224d3fee95cd9c23ea50f..4c622fab343eadf32a2468c26ead4e879739c2be 100644 (file)
@@ -49,7 +49,7 @@ Q_SIGNALS:
 
 private:
     Account *_account = nullptr;
-    QScopedPointer<Flow2Auth> _asyncAuth;
+    std::unique_ptr<Flow2Auth> _asyncAuth;
     Ui_Flow2AuthWidget _ui{};
 
 protected Q_SLOTS:
index 5e4c5fa2500577a9ede710bfc4731b57a684513d..dac9a0e608cbede5d82e186a598fd4ab9e550424 100644 (file)
@@ -1352,7 +1352,7 @@ PropagateDirectory::PropagateDirectory(OwncloudPropagator *propagator, const Syn
     , _subJobs(propagator)
 {
     if (_firstJob) {
-        connect(_firstJob.data(), &PropagatorJob::finished, this, &PropagateDirectory::slotFirstJobFinished);
+        connect(_firstJob.get(), &PropagatorJob::finished, this, &PropagateDirectory::slotFirstJobFinished);
         _firstJob->setAssociatedComposite(&_subJobs);
     }
     connect(&_subJobs, &PropagatorJob::finished, this, &PropagateDirectory::slotSubJobsFinished);
@@ -1395,7 +1395,7 @@ bool PropagateDirectory::scheduleSelfOrChild()
 
 void PropagateDirectory::slotFirstJobFinished(SyncFileItem::Status status)
 {
-    _firstJob.take()->deleteLater();
+    _firstJob.release()->deleteLater();
 
     if (status != SyncFileItem::Success
         && status != SyncFileItem::Restoration
index 1a96ece644c5d0e1efc16ee0aa13e62310805eec..ad191111184232cac196b6bc6adfee940eb99016 100644 (file)
@@ -315,7 +315,7 @@ class OWNCLOUDSYNC_EXPORT PropagateDirectory : public PropagatorJob
 public:
     SyncFileItemPtr _item;
     // e.g: create the directory
-    QScopedPointer<PropagateItemJob> _firstJob;
+    std::unique_ptr<PropagateItemJob> _firstJob;
 
     PropagatorCompositeJob _subJobs;
 
index 8d4915b488ead68ea43792ab06fd6bcd8bcc0f39..f691ce09da3a899ba8a0a97d0bfbc2515bf20ad4 100644 (file)
@@ -637,7 +637,7 @@ void SyncEngine::startSync()
 
     _remnantReadOnlyFolders.clear();
 
-    _discoveryPhase.reset(new DiscoveryPhase);
+    _discoveryPhase = std::make_unique<DiscoveryPhase>();
     _discoveryPhase->_leadingAndTrailingSpacesFilesAllowed = _leadingAndTrailingSpacesFilesAllowed;
     _discoveryPhase->_account = _account;
     _discoveryPhase->_excludes = _excludedFiles.data();
@@ -679,17 +679,17 @@ void SyncEngine::startSync()
     _discoveryPhase->_serverBlacklistedFiles = _account->capabilities().blacklistedFiles();
     _discoveryPhase->_ignoreHiddenFiles = ignoreHiddenFiles();
 
-    connect(_discoveryPhase.data(), &DiscoveryPhase::itemDiscovered, this, &SyncEngine::slotItemDiscovered);
-    connect(_discoveryPhase.data(), &DiscoveryPhase::newBigFolder, this, &SyncEngine::newBigFolder);
-    connect(_discoveryPhase.data(), &DiscoveryPhase::existingFolderNowBig, this, &SyncEngine::existingFolderNowBig);
-    connect(_discoveryPhase.data(), &DiscoveryPhase::fatalError, this, [this](const QString &errorString, ErrorCategory errorCategory) {
+    connect(_discoveryPhase.get(), &DiscoveryPhase::itemDiscovered, this, &SyncEngine::slotItemDiscovered);
+    connect(_discoveryPhase.get(), &DiscoveryPhase::newBigFolder, this, &SyncEngine::newBigFolder);
+    connect(_discoveryPhase.get(), &DiscoveryPhase::existingFolderNowBig, this, &SyncEngine::existingFolderNowBig);
+    connect(_discoveryPhase.get(), &DiscoveryPhase::fatalError, this, [this](const QString &errorString, ErrorCategory errorCategory) {
         Q_EMIT syncError(errorString, errorCategory);
         finalize(false);
     });
-    connect(_discoveryPhase.data(), &DiscoveryPhase::finished, this, &SyncEngine::slotDiscoveryFinished);
-    connect(_discoveryPhase.data(), &DiscoveryPhase::silentlyExcluded,
+    connect(_discoveryPhase.get(), &DiscoveryPhase::finished, this, &SyncEngine::slotDiscoveryFinished);
+    connect(_discoveryPhase.get(), &DiscoveryPhase::silentlyExcluded,
         _syncFileStatusTracker.data(), &SyncFileStatusTracker::slotAddSilentlyExcluded);
-    connect(_discoveryPhase.data(), &DiscoveryPhase::remnantReadOnlyFolderDiscovered, this, &SyncEngine::remnantReadOnlyFolderDiscovered);
+    connect(_discoveryPhase.get(), &DiscoveryPhase::remnantReadOnlyFolderDiscovered, this, &SyncEngine::remnantReadOnlyFolderDiscovered);
 
     ProcessDirectoryJob *discoveryJob = nullptr;
 
@@ -724,27 +724,27 @@ void SyncEngine::startSync()
         }();
 
         discoveryJob = new ProcessDirectoryJob(
-            _discoveryPhase.data(),
+            _discoveryPhase.get(),
             pinState,
             path,
             singleItemDiscoveryOptions().discoveryDirItem,
             {},
             localQueryMode,
             _journal->keyValueStoreGetInt("last_sync", 0),
-            _discoveryPhase.data()
+            _discoveryPhase.get()
         );
     } else {
         discoveryJob = new ProcessDirectoryJob(
-            _discoveryPhase.data(),
+            _discoveryPhase.get(),
             PinState::AlwaysLocal,
             _journal->keyValueStoreGetInt("last_sync", 0),
-            _discoveryPhase.data()
+            _discoveryPhase.get()
         );
     }
     
     _discoveryPhase->startJob(discoveryJob);
     connect(discoveryJob, &ProcessDirectoryJob::etag, this, &SyncEngine::slotRootEtagReceived);
-    connect(_discoveryPhase.data(), &DiscoveryPhase::addErrorToGui, this, &SyncEngine::addErrorToGui);
+    connect(_discoveryPhase.get(), &DiscoveryPhase::addErrorToGui, this, &SyncEngine::addErrorToGui);
 }
 
 void SyncEngine::slotFolderDiscovered(bool local, const QString &folder)
@@ -910,7 +910,7 @@ void SyncEngine::finalize(bool success)
     _stopWatch.stop();
 
     if (_discoveryPhase) {
-        _discoveryPhase.take()->deleteLater();
+        _discoveryPhase.release()->deleteLater();
     }
     s_anySyncRunning = false;
     _syncRunning = false;
@@ -1369,8 +1369,8 @@ void SyncEngine::abort()
     } else if (_discoveryPhase) {
         // Delete the discovery and all child jobs after ensuring
         // it can't finish and start the propagator
-        disconnect(_discoveryPhase.data(), nullptr, this, nullptr);
-        _discoveryPhase.take()->deleteLater();
+        disconnect(_discoveryPhase.get(), nullptr, this, nullptr);
+        _discoveryPhase.release()->deleteLater();
         qCInfo(lcEngine) << "Aborting sync in discovery...";
         finalize(false);
     }
index 63ab0a787e218573eb1d773d955f0eacf46c0011..2dc5bfa6b4a322f8ad19c9710d6bf44df29881bc 100644 (file)
@@ -339,7 +339,7 @@ private:
     QString _remotePath;
     QByteArray _remoteRootEtag;
     SyncJournalDb *_journal;
-    QScopedPointer<DiscoveryPhase> _discoveryPhase;
+    std::unique_ptr<DiscoveryPhase> _discoveryPhase;
     QSharedPointer<OwncloudPropagator> _propagator;
 
     QSet<QString> _bulkUploadBlackList;